package cn.china.springboot.controller;


import cn.china.springboot.service.StudentService;
import entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController
public class StudentController {

    @Autowired
    StudentService studentService;

    @RequestMapping("/insert")
    public  int insert(){
        Student student = new Student("hello",21,"女");
        return  studentService.insert(student);

    }

    @RequestMapping("/delete")
    public int delete(){
        int id = 17;
        return studentService.delete(id);
    }

    @RequestMapping("/update")
    public int update(){
        int id = 17;
        Student student = new Student(18, "王二", 25, "南");
        return studentService.update(student);
    }

    @RequestMapping("/selectList")
    public List<Student> selectlist(HttpServletResponse res){
        res.setHeader("Access-Control-Allow-Origin","*");
        List<Student> list = studentService.selectlist();

        return list;
    }

    @RequestMapping("/select")
    public Student select(int id){
        return studentService.select(id);
    }



}
